package com.woniuxy.educationplatform.service.impl;

import com.woniuxy.educationplatform.bean.MsgTaskBean;
import com.woniuxy.educationplatform.bean.SmsManageBean;
import com.woniuxy.educationplatform.mapper.MsgTaskMapper;
import com.woniuxy.educationplatform.mapper.SmsManageMapper;
import com.woniuxy.educationplatform.service.ISmsManage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Transactional;


import javax.annotation.Resource;
import java.util.List;

@Service
@Transactional(readOnly = true)
public class SmsManageImpl implements ISmsManage {

    @Resource
    private SmsManageMapper smsManageMapperImpl;
    @Resource
    private MsgTaskMapper msgTaskMapperImpl;


    //群发短信
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void InsertListOfSmsManageBean(List<SmsManageBean> list) {

        for (SmsManageBean smsManageBean: list)
        {
            smsManageMapperImpl.insert(smsManageBean);
        }

    }

    //向数据库中插入数据，返回插入的ID
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public int Insert(MsgTaskBean msgTask) {
        return msgTaskMapperImpl.Insert(msgTask);
    }


    //查询所有的任务, 传递一个接收筛选条件的MsgTaskBean  MsgTaskBean msgTaskBean
    @Override
    public List<MsgTaskBean> selectAll(MsgTaskBean msgTaskBean) {
        return msgTaskMapperImpl.selectAll(msgTaskBean);
    }



    //根据任务id，查询
    @Override
    public MsgTaskBean selectByID(Long ID) {
        return msgTaskMapperImpl.selectByID(ID);
    }


    //逻辑删除(即修改）
    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void deleteByID(Long taskID) {
        msgTaskMapperImpl.deleteByID(taskID);
    }

    @Override
    public List<SmsManageBean> selectRecordByTaskID(Long taskID) {
        return smsManageMapperImpl.selectRecordByTaskID(taskID);
    }

    @Transactional(isolation = Isolation.REPEATABLE_READ,rollbackFor = Exception.class)
    @Override
    public void updateTask(MsgTaskBean msgTaskBean) {
        msgTaskMapperImpl.updateTask(msgTaskBean);
    }

}
